package com.lilihub.miaosha.dao;

import com.lilihub.miaosha.domain.MiaoshaOrder;
import com.lilihub.miaosha.domain.OrderInfo;
import org.apache.ibatis.annotations.*;

/**
 * @BelongsProject: miaosha
 * @BelongsPackage: com.lilihub.miaosha.dao
 * @Author: LiYing
 * @CreateTime: 2021-04-27 12:56
 * @Description:
 */
@Mapper
public interface OrderDao {


    @Select("select * from miaosha_order where user_id = #{userId} and goods_id = #{goodsId}")
    MiaoshaOrder getMiaoshaOrderByUserIdGoodsId(@Param("userId") Long userId, @Param("goodsId") long goodsId);


    @Insert("insert into order_info(user_id,goods_id,goods_name,goods_count,goods_price,order_channel,status,create_date)" +
            "values(#{userId},#{goodsId},#{goodsName},#{goodsCount},#{goodsPrice},#{orderChannel},#{status},#{createDate})")
    @SelectKey(keyColumn ="id",keyProperty = "id",resultType = long.class,before = false,statement = "select last_insert_id()")
    long insert(OrderInfo orderInfo);

    @Insert("insert into miaosha_order(user_id,order_id,goods_id) values(#{userId},#{orderId},#{goodsId})")
    long insertMiaoshaOrder(MiaoshaOrder miaoshaOrder);

    @Select("select * from order_info where id = #{orderId}")
    OrderInfo getOrderById(@Param("orderId") long orderId);

    @Delete("delete from order_info")
    void deleteorderInfo();

    @Delete("delete from miaosha_order")
    void deleteMiaoshaOrders();
}
